package com.beijiteshop.shop.ui.detail.adapter

import android.view.View
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import com.beijiteshop.shop.R
import com.beijiteshop.shop.databinding.ItemTextFlextBoxBinding
import com.beijiteshop.shop.model.entity.CheckBoxEntity
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder

/**
 * @Author LiaoZhongKai
 * @Date 2021/3/5 13:59
 * @Description 纯文字流式布局单选列表adapter
 */
class TextFlexBoxAdapter(data: MutableList<CheckBoxEntity<String>>, @DrawableRes private val itemBgResId: Int, @ColorRes private val itemColorRes: Int)
    : BaseQuickAdapter<CheckBoxEntity<String>,BaseDataBindingHolder<ItemTextFlextBoxBinding>>(R.layout.item_text_flext_box,data) {

    override fun convert(holder: BaseDataBindingHolder<ItemTextFlextBoxBinding>, item: CheckBoxEntity<String>) {
        val binding = holder.dataBinding
        binding?.run {
            text = item.data
            itemFlexBoxTv.apply {
                isSelected = item.isSelected
                setTextColor(ContextCompat.getColor(context,itemColorRes))
                setBackgroundResource(itemBgResId)
            }
        }
    }
//
//    override fun setOnItemClick(v: View, position: Int) {
//        //设置item的选中、未选择状态
//        val curPosition = getCurSelectPosition()
//        if (curPosition != -1 && curPosition != position){
//            data.forEachIndexed { index, checkBoxBean ->
//                checkBoxBean.isSelected = index == position
//            }
//            notifyItemChanged(curPosition)
//            notifyItemChanged(position)
//        }
//        super.setOnItemClick(v, position)
//    }
//
//    /**
//     * 获取当前选中的Item的position
//     */
//    private fun getCurSelectPosition(): Int{
//        var position = -1
//        data.forEachIndexed { index, checkBoxBean ->
//            if (checkBoxBean.isSelected){
//                position = index
//            }
//        }
//        return position
//    }
//

}